#!/usr/bin/env python


def options(opt):
	opt.add_option('--g2d-includes', action = 'store', default = '', help = 'path to the directory where the g2d.h header is')
	opt.add_option('--g2d-libs', action = 'store', default = '', help = 'path to the directory where the g2d library is')
	opt.add_option('--disable-g2d', action = 'store_true', default = False, help = 'disable G2D plugin [default: enabled]')
	opt.recurse('pango')


def configure(conf):
	if conf.options.disable_g2d:
		return

	if not conf.env['WITH_GSTVIDEO']:
		return

	from waflib.Build import Logs
	g2d_libpath = [conf.options.g2d_libs] if conf.options.g2d_libs else []
	g2d_includes = [conf.options.g2d_includes] if conf.options.g2d_includes else []
	if conf.check_cc(mandatory = 0, libpath = g2d_libpath, lib = 'g2d', uselib_store = 'IMXG2D') and \
	   conf.check_cc(mandatory = 0, includes = g2d_includes, header_name = 'g2d.h', uselib_store = 'IMXG2D'):
		Logs.pprint('GREEN', 'G2D elements will be built')
		conf.env['G2D_ELEMENTS_ENABLED'] = 1
	else:
		Logs.pprint('RED', 'G2D elements will not be built - headers and/or libraries not found')

	conf.recurse('pango')



def build(bld):
	pango_source = []
	if bld.env['G2D_PANGO_ELEMENTS_ENABLED']:
		pango_source += bld.path.ant_glob('pango/*.c')
	if bld.env['G2D_ELEMENTS_ENABLED']:
		bld(
			features = ['c', bld.env['CLIBTYPE']],
			includes = ['.', '../..'],
			uselib = bld.env['COMMON_USELIB'] + ['PANGO', 'CAIRO', 'PANGOCAIRO', 'IMXG2D'],
			use = ['gstimxcommon', 'gstimxblitter', 'gstimxcompositor'],
			target = 'gstimxg2d',
			source = bld.path.ant_glob('*.c') + pango_source,
			install_path = bld.env['PLUGIN_INSTALL_PATH']
		)
